<?php
namespace Home\Controller;

use Home\Common\Common;
class LeaveController extends Common{
    public function show(){
        //请假申请表
        $leave = M('leaveinfo');
        //搜索
        if (empty($_GET['search']) || empty($_GET['value'])) {
            $where = '';
        } else {
            //where条件的附近一定要加上空格
            $where = ' and stf_name like "%' . $_GET['value'] . '%"';
            $this->assign('value', $_GET['value']);
        }
        $count = $leave->join('staffinfo on staffinfo.stf_id=leaveinfo.stf_id')->where('state=1'.$where)->count();  //统计输出到页面的数据总条数
        $page = new \Think\Page($count, 8); //实例化thinkphp的分页类
        $show = $page->show(); //输出分页
        //limit('0,5')   limit('6,10')
        //连表查询数据[主表（调岗表)关联子表(员工表、部门表、岗位表)]
       $leaveList = $leave->join('staffinfo on staffinfo.stf_id=leaveinfo.stf_id')->where('state=1'.$where)->limit($page->firstRow . ',' . $page->listRows)->order('ln_id')->select();
        $this->assign('count', $count);  //将计数的数据输出到视图
        $this->assign('show', $show);  //将分页信息输出到视图
        $this->assign('leaveList', $leaveList);  //将数据输出到视图
        //请假类型表
        $type=M('atrtypeinfo');
        $typeList=$type->select();
        $this->assign('typeList',$typeList);
        //员工表
        $staff = M('staffinfo');
        $staffList = $staff->select();
        $this->assign('staffList', $staffList);
        $this->display();
    }
    public function del()
    {
        if (empty($_GET['ln_id'])) {
            $this->error('参数错误');
        } else {
            $record = M('leaveinfo');
            $record->where('ln_id=' . $_GET['ln_id'])->save(array('state' => 0));
            $this->success('隐藏成功', U('show'));
        }
    }
}
